/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package percussiongenerator.commands;

import org.jfonia.connect5.intervals.LinkedDoubleIntervalList;
import org.jfonia.connect5.intervals.LinkedIntIntervalList;
import org.jfonia.connect5.intervals.LinkedIntIntervalList;
import org.jfonia.connect5.intervals.LinkedLongIntervalList;
import org.jfonia.model.Staff;

/**
 *
 * @author Jannes Plyson
 */
public class Stretch implements ICommand{
    Object list;
    Object oldValue;
    Object newValue;

    public Stretch(LinkedIntIntervalList list, Integer newValue){
        this.newValue = newValue;
        this.list = list;
    }

    public Stretch(LinkedLongIntervalList list, Long newValue){
        this.newValue = newValue;
        this.list = list;
    }

    public Stretch(LinkedDoubleIntervalList list, Double newValue){
        this.newValue = newValue;
        this.list = list;
    }

    public Stretch(Staff staff, Integer newValue){
        this.newValue = newValue;
        list = staff;
    }

    public void execute() {
        if(list instanceof LinkedIntIntervalList){
            oldValue = ((LinkedIntIntervalList)list).getDifference();
            ((LinkedIntIntervalList)list).stretch((Integer)newValue);
        }else if(list instanceof LinkedLongIntervalList){
            oldValue = ((LinkedLongIntervalList)list).getDifference();
            ((LinkedLongIntervalList)list).stretch((Long)newValue);
        }else if(list instanceof LinkedDoubleIntervalList){
            oldValue = ((LinkedDoubleIntervalList)list).getDifference();
            ((LinkedDoubleIntervalList)list).stretch((Long)newValue);
        }else{
            oldValue = ((Staff)list).getLength();
            ((Staff)list).stretch((Integer)newValue);
        }
    }

    public void undo() {        
        if(list instanceof LinkedIntIntervalList){
            ((LinkedIntIntervalList)list).stretch((Integer)oldValue);
        }else if(list instanceof LinkedLongIntervalList){
            ((LinkedLongIntervalList)list).stretch((Long)oldValue);
        }else if(list instanceof LinkedDoubleIntervalList){
            ((LinkedDoubleIntervalList)list).stretch((Long)oldValue);
        }else{
            ((Staff)list).stretch((Integer)oldValue);
        }
    }

}
